#ifndef zt_config_h
#define zt_config_h

#include <signal.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <stdarg.h>
#include <fcntl.h>
#include <errno.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>

#ifdef _MSC_VER
#include <windows.h>
#include <WinInet.h>
#include <WinReg.h>
#include <winsock.h>
#include <process.h>
#include <tchar.h>
#include <io.h>

#ifndef ZT_LIB_STATIC
	#ifdef ZT_LIB_EXPORTS
		#define ZT_API	_declspec(dllimport)
	#else
		#define ZT_API	_declspec(dllexport)
	#endif
#else
	#define ZT_API
#endif	
		
#define zt_inline			__inline
		
#if _MSC_VER>1200
	typedef intptr_t		zt_int_t;
	typedef uintptr_t		zt_uint_t;
#else
	typedef int				zt_int_t;
	typedef unsigned int	zt_uint_t;
#endif
#define zt_int64_t 			__int64
#define zt_uint64_t 		unsigned __int64
#define zt_socket_t			SOCKET

#define ZT_S64				"%I64d"
#define ZT_US64				"%I64u"

#define zt_errno			GetLastError()
#define zt_socket_errno		WSAGetLastError()
#define zt_close(fd)		closesocket(fd)
#define zt_shutdown(fd)		shutdown(fd,SD_BOTH)

#else
/* Linux/BSD */
#include <stdint.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>        /* TCP_NODELAY, TCP_CORK */
#include <arpa/inet.h>
#include <netdb.h>
#include <pthread.h>

#define ZT_API
#define zt_inline			inline

typedef intptr_t			zt_int_t;
typedef uintptr_t			zt_uint_t;
#define zt_int64_t 			long long
#define zt_uint64_t 		unsigned long long
#define zt_socket_t			int

#define ZT_S64				"%lld"
#define ZT_US64				"%llu"

#define zt_errno			errno
#define zt_socket_errno		errno
#define zt_close(fd)		close(fd)
#define zt_shutdown(fd)		shutdown(fd,SHUT_RDWR)

#endif

#define ZT_OK				0
#define ZT_ERR				-1

#define zt_align(d,a)		(((d)+(a-1))&~(a-1))

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif /* C++ */
#endif /* zt_config_h */
